package com.lh.web.service.impl.ovmalUser;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.lh.common.entity.admin.User;
import com.lh.common.enums.IsDel;
import com.lh.common.enums.TrueFalseEnum;
import com.lh.common.enums.UserTypeEnum;
import com.lh.common.utils.Constant;
import com.lh.common.utils.MD5Encrypt;
import com.lh.common.utils.PageUtils;
import com.lh.web.dao.admin.UserMapper;
import com.lh.web.service.serviceAdmin.ovmalUser.UserService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author FH
 * @ClassName: UserServiceImpl
 * @Description: (类作用)
 * @date: 2020-05-12 9:37
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public PageUtils queryUserList(Map<String, Object> param, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> notices = this.baseMapper.queryUserList(param);
        return new PageUtils(notices);
    }

    @Override
    public void batchInsertUser(List<User> list) {
        list.forEach(user -> {
            try {
                int i = this.baseMapper.queryUserRobot(user.getPhone());
                if(i <= Constant.RESULT.SC0){
                    user.setPassword(MD5Encrypt.md5Small("123456"));
                    user.setType(UserTypeEnum.ROBOT);
                    user.setStatus(TrueFalseEnum.TRUE);
                    user.setIsDel(IsDel.NO);
                    this.baseMapper.insert(user);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }

    @Override
    public int queryUserRobot(String phone) {
        return this.baseMapper.queryUserRobot(phone);
    }
}
